package com.designpattern.sixchapter.remotecontrol;

import com.designpattern.sixchapter.first.Command;

public class RemoteControl {
	
	Command[] onCommands;
	Command[] offCommands;
	public RemoteControl() {
		onCommands = new Command[7];
		offCommands = new Command[7];
		NoCommand noCommand = new NoCommand();
		for (int i = 0; i < offCommands.length; i++) {
			onCommands[i] = noCommand;
			offCommands[i] = noCommand;
		}
	}
	
	public void setCommand(int slot, Command onCommand, Command offCommand) {
		onCommands[slot] = onCommand;
		offCommands[slot] = offCommand;
	}
	
	public void onBtnWasPushed(int slot)  {
		onCommands[slot].execute();
	}
	
	public void offBtnWasPushed(int slot)  {
		offCommands[slot].execute();
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\n -----remote control ----\n");
		for (int i = 0; i < offCommands.length; i++) {
			
			sb.append("slot: " + i + "  " + onCommands[i].getClass().getName() + " \n"
					 + offCommands[i].getClass().getName() + "\n");
		}
		
		return sb.toString();
		
	}
	
	

}
